<?php
    namespace app\api\model;
    use think\Model;
    
    class Poets extends Model
    {
        protected $hidden = ['created_at', 'updated_at'];

        # 获取作者
        public static function getAuthors($page,$limit){
            $author = self::with('poetries')
                    ->paginate($limit);
            foreach($author as $item){
                $item['len'] = count($item['poetries']);
            }
            return $author;
        }

        # 链表查询
        public function poetries()
        {
            return $this->hasMany('Poetries','poet_id');
        }

        # 查询作者
        public static function searchAuthor($name)
        {
            $author = self::where('name','LIKE' , '%'.$name.'%')->limit(30)->select();
            return $author;
        }


    }